#ifndef DW_GRAPHICS_ANIMATION_H
#	define DW_GRAPHICS_ANIMATION_H

#include "base/pointer.h"

namespace dw {
	namespace graphics {

using maths::Point3f;
using maths::Quaternionf;
using maths::Vector3f;
using maths::Matrix3f;
using maths::Matrix4f;

/* Class used to manage keyframe animation. */
class Animation
{
public:

	template< typename T >
	struct Key
	{
		float time;
		T value;
	};

	/** Interpolation mode. */
	enum InterpolationMode
	{
		NONE,
		LINEAR,
		SPLINE
	};

public:
	
	/** Default ctor. */
	Animation();

	/**	Create a named animation. */
	Animation(const std::string& name);



	const std::string& getName() const { return _name; }

	void setName(const std::string& name) { _name = name; }



	unsigned getNumPosKeys() const { return static_cast< unsigned >(_posKeys.size()); }

	unsigned getNumRotKeys() const { return static_cast< unsigned >(_rotKeys.size()); }

	unsigned getNumScaleKeys() const { return static_cast< unsigned >(_scaleKeys.size()); }



	Point3f getPosition(const float& t);

	Quaternionf getRotation(const float& t);

	Vector3f getScale(const float& t);



	void addPosKey(const float& t, const Point3f& p);

	void addRotKey(const float& t, const Quaternionf& p);

	void addScaleKey(const float& t, const Vector3f& p);
	

private:

	typedef std::map< float, Key< Point3f > >			PosKeyMap;

	typedef std::map< float, Key< Quaternionf > >	RotKeyMap;

	typedef std::map< float, Key< Vector3f > >			ScaleKeyMap;

private:

	/** Animation name*/
	std::string _name;

	PosKeyMap _posKeys;
	
	RotKeyMap _rotKeys;
	
	ScaleKeyMap _scaleKeys;



	PosKeyMap::iterator _currentPosKey;

	RotKeyMap::iterator _currentRotKey;

	ScaleKeyMap::iterator _currentScaleKey;

	
	/// Interpolation mode used by Animation::frame
	InterpolationMode _interpolationMode;

private:

	///	iostream compatible serialization function
	friend	
	std::ostream& operator<<(std::ostream& os, const Animation& animation);
	
	///	iostream compatible deserialization function
	friend
	std::istream& operator>>(std::istream& is, Animation& animation);

};

typedef base::Pointer< Animation > AnimationPtr;

	} // namespace graphics
} // namespace dw

#endif // !DW_GRAPHICS_ANIMATION_H
